import request from "@/utils/request";
import { LossForm, LossQuery } from "./types";
import { AxiosPromise } from "axios";

/**
 * 损失细类分页数据
 *
 * @param queryParams
 */
export function getLossPage(
	queryParams: LossQuery
): AxiosPromise<PageResult<[]>> {
	return request({
		url: '/api/v1/loss/page',
		method: 'get',
		params: queryParams
	});
}


/**
 * 获取损失细类表单数据
 *
 * @param queryParams
 */
export function getLossForm(lossId: number): AxiosPromise<LossForm> {
	return request({
		url: '/api/v1/loss/' + lossId + '/form',
		method: 'get'
	});
}

/**
 * 保存损失细类
 *
 * @param data
 */
export function saveLoss(data: LossForm) {
  return request({
    url: "/api/v1/loss",
    method: "post",
    data: data,
  });
}

/**
 * 删除损失细类
 *
 * @param ids
 */
export function deleteLoss(ids: string) {
	return request({
		url: '/api/v1/loss/' + ids,
		method: 'delete'
	});
}

/**
 * 导入损失细类
 *
 * @param file
 */
export function importLoss(file: File) {
	const formData = new FormData();
	formData.append('file', file);
	return request({
		url: '/api/v1/loss/_import',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	});
}

/**
 * 导出损失细类
 *
 * @param queryParams
 * @returns
 */
export function exportLoss() {
	return request({
		url: '/api/v1/loss/_export',
		method: 'get',
		responseType: 'arraybuffer'
	});
}

/**
 * 获取损失细类表单数据
 *
 * @param queryParams
 */
export function getNextCode(code: string): AxiosPromise<LossForm> {
	return request({
		url: '/api/v1/loss/nextCode/' + code,
		method: 'get'
	});
}

/**
 * 获取损失细类表单数据
 *
 * @param queryParams
 */
export function listAll(): AxiosPromise<LossForm[]> {
	return request({
		url: '/api/v1/loss/list',
		method: 'get'
	});
}
